<template>
  <div class="nav-header">
    <i
      class="fold-menu"
      :class="isFold ? 'el-icon-s-unfold' : 'el-icon-s-fold'"
      @click="handleFoldClick"
    />
    <div class="content">
      <wj-breadcrumb :breadcrumbs="breadcrumbs" />
      <user-info />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { useStore } from '@/store'
import WjBreadcrumb from '@/base-ui/wj-breadcrumb'
import UserInfo from './user-info.vue'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
export default defineComponent({
  name: 'nav-header',
  emits: ['foldChange'],
  components: {
    UserInfo,
    WjBreadcrumb
  },
  setup(props, { emit }) {
    const isFold = ref(false)

    const store = useStore()
    const route = useRoute()

    const breadcrumbs = computed(() => {
      const userMenu = store.state.login.userMenu
      const currentPath = route.path
      return pathMapBreadcrumbs(userMenu, currentPath)
    })

    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }

    return { isFold, breadcrumbs, handleFoldClick }
  }
})
</script>

<style lang="less" scoped>
.nav-header {
  display: flex;
  width: 100%;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .content {
    flex: 1;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
